const http = require('http')
const fs = require('fs')

http.createServer(function (request, response) {
  console.log(request.url)
  // 为了简单,任何请求都直接返回json数据
  fs.readFile('./data.json', 'utf-8', (err, file) => { 
    // response.setHeader('Access-Control-Allow-Origin',"*")
    response.setHeader('Cache-control','max-age=10')
    response.writeHeader(200, {
      'Content-Type': 'application/json;charset:utf-8'
    })
    response.end(file)
  })
}).listen(22222, err => {
  err ? console.log(err.message) : console.log(`服务已经启动,在端口号:22222`)
})